package com.jeremy.comutils.utils;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Date;


public class CmdTest {
    public static void main(String[] args) {
        BufferedReader br = null;
        try {
            String command = "ping baidu.com -t";
            System.out.println(command);
            Process p = Runtime.getRuntime().exec("cmd.exe /c " + command);
            br = new BufferedReader(new InputStreamReader(p.getInputStream(), Charset.forName("GBK")));
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(new Date() + "   " + line);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {

            if (br != null) {
                try {
                    br.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

    }

}